package com.gerryrun.lib_skin;

import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class SkinPreference {

    private static Application mContext;
    static SharedPreferences.Editor editor;
    String skinPath = "gerry_skin";

    public static void init(Application context) {
        mContext = context;
        editor = getInstance().editor;
    }


    public String getSkin() {
        return getPreferences().getString(skinPath, "");
    }

    public void setSkinPath(String path) {
        getInstance().editor.putString(skinPath, path).apply();
    }

    public void reset() {
        setSkinPath("");
    }

    private static class Holder {
        private static SkinPreference instance = new SkinPreference();

        public static SkinPreference getInstance() {
            return instance;
        }
    }

    public static SkinPreference getInstance() {
        return Holder.getInstance();
    }

    private static SharedPreferences getPreferences() {
        SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
        editor = defaultSharedPreferences.edit();
        return defaultSharedPreferences;
    }
}
